package ym.controller.front.house;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ym.pojo.HousePlot;
import ym.service.HousePlotService;
import ym.vo.BaseResult;

import java.util.List;

/**
 * 小区
 */
@CrossOrigin
@RestController
@RequestMapping("/front/housePlot")
public class FrontHousePlotCon {
    @Autowired
    private HousePlotService housePlotService;
    /**
     * 根据id查询【封装在租房源，更新在租房源数量】
     *
     * @param housePlotId
     * @return 查询结果
     */
    @GetMapping("/findById")
    public BaseResult findById(Integer housePlotId) {
        HousePlot housePlot = housePlotService.findById(housePlotId);
        return BaseResult.ok(housePlot);
    }

    /**
     * 查询所有
     *
     * @return
     */
    @GetMapping("/findAll")
    public BaseResult findAll() {
        List<HousePlot> all = housePlotService.findAll();
        return BaseResult.ok(all);
    }

    /**
     * 分页查询
     *
     * @param search 搜索条件
     * @param page   当前页
     * @param size   每页大小
     * @return
     */
    @GetMapping("/search")
    @PreAuthorize("hasAnyAuthority('/house')")
    public BaseResult search(String search, int page, int size) {
        Page<HousePlot> housePlotPage = housePlotService.search(search, page, size);
        return BaseResult.ok(housePlotPage);
    }
}
